! function (t, e) {
  "function" == typeof define && define.amd ? define(e) : "undefined" != typeof module && module.exports ? module.exports = e() : t.easydate = e()
}(this, function () {
  function t(t) {
    return new e(t)
  }

  function e(t) {
    this.date = n(t)
  }

  function n(t) {
    var n;
    return n = "string" == typeof t ? new Date(t.replace(/-/g, "/")) : "number" == typeof t ? new Date(t) : t && "[object date]" === Object.prototype.toString.call(t).toLowerCase() ? new Date(t.getTime()) : t instanceof e ? new Date(t.valueOf()) : new Date
  }

  function i(t) {
    return 10 > t ? "0" + t : t
  }
  return e.prototype = {
      getWeekth: function () {
        return t.getWeekth(this.date)
      },
      getMonthDays: function () {
        return t.getMonthDays(this.date)
      },
      isValid: function () {
        return !isNaN(this.date.getFullYear())
      },
      isLeapYear: function () {
        return t.isLeapYear(this.date.getFullYear())
      },
      isBefore: function (t) {
        return this.date.getTime() < n(t || "").getTime()
      },
      isAfter: function (t) {
        return this.date.getTime() > n(t || "").getTime()
      },
      isSame: function (t) {
        return this.date.getTime() === n(t || "").getTime()
      },
      isBetween: function (t, e) {
        var i, o = this.date.getTime(),
          r = n(t || "").getTime(),
          a = n(e || "").getTime();
        return r > a && (i = r, r = a, a = i), o >= r && a >= o
      },
      diff: function (e, n) {
        return t.diff(this.date, e, n)
      },
      format: function (t) {
        var e = this.date,
          n = e.getFullYear(),
          o = (n + "").substring(2),
          r = e.getMonth() + 1,
          a = e.getDate(),
          u = e.getHours(),
          s = u > 12 ? u - 12 : u,
          g = e.getMinutes(),
          h = e.getSeconds(),
          f = {
            yyyy: n,
            yy: o,
            MM: i(r),
            M: r,
            dd: i(a),
            d: a,
            HH: i(u),
            H: u,
            hh: i(s),
            h: s,
            mm: i(g),
            m: g,
            ss: i(h),
            s: h,
            S: e.getMilliseconds(),
            tt: u > 12 ? "下午" : "上午"
          };
        ("string" != typeof t || "" === t) && (t = "yyyy/MM/dd HH:mm:ss");
        for (var l in f) f.hasOwnProperty(l) && (t = t.replace(new RegExp(l, "g"), f[l]));
        return t
      },
      calc: function (t, e) {
        var n, i = this.date,
          o = 1e3,
          r = 60 * o,
          a = 60 * r,
          u = 24 * a,
          s = {
            second: o,
            minute: r,
            hour: a,
            day: u
          },
          g = i.getTime();
        return n = "month" === t ? i.setMonth(i.getMonth() + e) : "year" === t ? i.setYear(i.getFullYear() + e) : g + (s[t] || 0) * e, this.date = new Date(n), this
      },
      toDatePart: function () {
        var t = this.date;
        return this.date = new Date(t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate()), this
      },
      clone: function () {
        return t(this.date.getTime())
      }
    },
    function () {
      var t, n, i = ["getFullYear", "getDate", "getDay", "getHours", "getMinutes", "getSeconds", "getMilliseconds", "valueOf", "toString", "toTimeString", "toDateString", "toGMTString", "toUTCString", "toLocaleString", "toLocaleTimeString", "toLocaleDateString"],
        o = ["setFullYear", "setMonth", "setDate", "setHours", "setMinutes", "setSeconds", "setMilliseconds"];
      for (t = 0, n = i.length; n > t; t++) ! function (t) {
        e.prototype[t] = function () {
          return this.date[t]()
        }
      }(i[t]);
      for (e.prototype.getMonth = function () {
          return this.date.getMonth() + 1
        }, t = 0, n = o.length; n > t; t++) ! function (t) {
        e.prototype[t] = function (e) {
          return this.date[t]("setMonth" === t ? e - 1 : e), this
        }
      }(o[t])
    }(), t.isLeapYear = function (t) {
      return t = Number(t), isNaN(t) ? !1 : t % 400 === 0 || t % 4 === 0 && t % 100 !== 0
    }, t.isValid = function (t) {
      var e = n(t || "");
      return !isNaN(e.getFullYear())
    }, t.getWeekth = function (t) {
      var e = n(t || ""),
        i = e.getFullYear();
      if (isNaN(i)) return 0 / 0;
      var o = new Date(i, 0, 1),
        r = o.getDay(),
        a = Math.floor((e.getTime() - o.getTime()) / 864e5),
        u = Math.floor((a + r) / 7) + 1;
      return u
    }, t.getMonthDays = function (t) {
      var e = n(t || ""),
        i = e.getMonth() + 1;
      return isNaN(i) ? 0 / 0 : new Date(e.getFullYear(), i, 0).getDate()
    }, t.diff = function (t, e, i) {
      var o, r, a, u, s, g, h, f, l, d, c, m, y = 1e3,
        M = 60 * y,
        D = 60 * M,
        T = 24 * D,
        p = {
          second: y,
          minute: M,
          hour: D,
          day: T
        },
        w = "json" === i;
      return t = n(t || ""), e = n(e || ""), t > e && (m = t, t = e, e = m), a = t.getTime(), u = e.getTime(), h = Math.abs(u - a), isNaN(a) || isNaN(u) ? 0 / 0 : a === u ? 0 : (c = Math.floor(h / (p[i] || T)), w && (f = {
        year: null,
        month: null,
        day: Math.floor(h / p.hour / 24),
        hour: Math.floor(h / p.hour % 24),
        minite: Math.floor(h / p.minute % 60),
        second: Math.floor(h / p.second % 60),
        maxUnit: ""
      }, f.maxUnit = 0 !== f.day ? "day" : 0 !== f.hour ? "hour" : 0 !== f.minite ? "minite" : "second"), "json|month|year".indexOf(i) >= 0 && ((o = new Date(t.getTime())).setDate(1), (r = new Date(e.getTime())).setDate(1), s = (a - o.getTime()) / T, g = (u - r.getTime()) / T, l = 12 * r.getFullYear() + r.getMonth() - (12 * o.getFullYear() + o.getMonth()), s > g && l--, w ? (f.day = Math.floor((e.getTime() - t.setMonth(t.getMonth() + l)) / T), l > 0 && (f.maxUnit = "month")) : c = l), "json|year".indexOf(i) >= 0 && (d = Math.floor(l / 12), w ? (f.year = d, f.month = l % 12, d > 0 && (f.maxUnit = "year")) : c = d), w ? f : c)
    }, t
});
